<?php
//data/init.php
//创建到服务器的连接，连接数据库  mysqli_connect(IP, 用户名，密码，数据库名)  连接数据库  
$link = @mysqli_connect('127.0.0.1','root','','test');
// 准备sql语句
$name = $_POST['user'];
$pwd = $_POST['pwd'];
$sql = "insert into login values(null,'$name','$pwd')";
// 执行sql语句
$res = mysqli_query($link, $sql);

if ($res) {
  echo json_encode(array(
    "code" => 200,
    "msg" => "注册成功"
  ));
} else {
  echo json_encode(array(
    "code" => 500,
    "msg" => "网络错误，请重试"
  ));
}